package com.laosg.framework.recaptcha;

import com.laosg.framework.recaptcha.easyCaptch.base.Captcha;
import com.laosg.framework.recaptcha.easyCaptch.out.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>description: some thing </p>
 *
 * @author kevinruan@pano.im
 * @date 2020/5/12
 */
@RestController
@RequestMapping("/cap")
public class CaptchaController {




    @GetMapping("/{type}")
    public void get(@PathVariable("type")String type, HttpServletRequest request, HttpServletResponse response) throws IOException {
        switch (type) {
            case "arit":
                // 算术类型
                ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
                captcha.setLen(3);  // 几位数运算，默认是两位
                captcha.getArithmeticString();  // 获取运算的公式：3+2=?
                String text = captcha.text();// 获取运算的结果：5
                System.out.println(text);
                captcha.out(response.getOutputStream());
                break;
            case "ch":
                ChineseCaptcha ch = new ChineseCaptcha(130, 48);
                System.out.println(ch.text());
                ch.out(response.getOutputStream());
                break;
            case "chgif":
                ChineseGifCaptcha chgif = new ChineseGifCaptcha(130, 48);
                System.out.println(chgif.text());
                chgif.out(response.getOutputStream());
                break;
            case "gif":
                GifCaptcha gif = new GifCaptcha(130, 48);
                System.out.println(gif.text());
                gif.out(response.getOutputStream());
                break;
            case "spc":
                SpecCaptcha sp = new SpecCaptcha(130, 48);
                sp.text();  // 获取验证码的字符
                sp.textChar();  // 获取验证码的字符数组
                System.out.println(sp.text());
                sp.out(response.getOutputStream());
                break;
            default:break;

        }
    }
}
